查看npz文件信息
import numpy as np
import os
from matplotlib import pyplot as plt
sampled_batch = np.load("train_npz/case0005_slice000.npz")
image = sampled_batch["image"].T
plt.imshow(image, cmap='gray')
plt.show()
label = sampled_batch["label"].T
plt.imshow(label, cmap='gray')
plt.show()
查看文件尺寸信息
sampled_batch["image"].shape,sampled_batch["label"].shape
((512, 512), (512, 512))
查看文件包含哪些信息
sampled_batch.files
[‘image’, ‘label’]
查看图像中的像素范围
sampled_batch['image'].min(), sampled_batch['image'].max()
(0.0, 1.0)
关闭文件
sampled_batch.close()
查看h5文件信息
import h5py
f = h5py.File('test_vol_h5/case0001.npy.h5', 'r')
for key in f.keys():
print(f[key].name)
print(f[key].shape)
/image
(147, 512, 512)
/label
(147, 512, 512)
查看图像shape
f['image'].shape,f['label'].shape
((147, 512, 512), (147, 512, 512))